package com.hyzx.qbasic.admin.common.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.HashSet;
import java.util.Set;

/**
 * Created by 黄江华 on 2017/11/23
 */

@Configuration
@EnableSwagger2
public class SwaggerConfig {
    @Bean
    public Docket systemRestApi() {
        Set<String> types = new HashSet<>(1);
        types.add("application/json");

        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.hyzx.qbasic.admin.controller.system"))
                .build()
                .groupName("系统管理")
                .apiInfo(apiInfo())
                .useDefaultResponseMessages(false)
                .consumes(types)
                .produces(types);
    }

    @Bean
    public Docket operationRestApi() {
        Set<String> types = new HashSet<>(1);
        types.add("application/json");

        return new Docket(DocumentationType.SWAGGER_2)
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.hyzx.qbasic.admin.controller.operations"))
                .build()
                .groupName("运维工具")
                .apiInfo(apiInfo())
                .useDefaultResponseMessages(false)
                .consumes(types)
                .produces(types);
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("QBasic开发框架接口文档")
                .version("1.0.0")
                .build();
    }
}
